import {db} from "@/lib/db";


export async function getArticleByTime(m: number) {

    return db.$queryRaw`
        SELECT art_title,art_url,created_at from tb_article 
        WHERE created_at >= current_timestamp - (${m} || 'minutes')::interval
        ORDER BY created_at desc`;
}


export const getArticlesByKeywords = async (keywords: string[]) => {
    if (keywords.length === 0) return [];
    const reg_str = keywords.join('|').replace(' ', '');
    return db.$queryRaw`
        SELECT art_title,art_content,art_url,created_at FROM tb_article WHERE art_title ~* ${reg_str} AND created_at >= now()-'3 hours'::interval ORDER BY created_at desc   
    `;
};